package com.whsxt.code;

import java.util.Scanner;

/**
 * @author CodeYang
 * @Description 3.输入一批整数，使用循环求出最大值与最小值，输入0时结束。
 * @Date 2020/12/6 23:15
 */
public class MaxAndMinArr {
    public static void main(String[] args) {
        int number,max,min;
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入一批整数: 输入0 时结束!");
        number = scanner .nextInt();
        max = min = number;
        while (number !=0){
            System.out.println("请继续输入, 输入为0结束");
            number = scanner.nextInt();
            if (number !=0){
                // 判断 n != 0 时才进入,要不然最小值永远是 0
                if (number > max ) max = number;
                if (number < min) min = number;
            }

        }
        System.out.println("最大值:"+ max+"\t 最小值:"+min);

    }
}
